package com.dyz.swordFingerOffer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;

/**
 * @author: daiyizheng
 * @date: 2021/6/9 21:30
 * @description:
 */
public class FindNumsAppearOnce56 {
    public static void main(String[] args) {
        int[] arr = new int []{1,4,1,6};
        int[] ints = new FindNumsAppearOnce56().FindNumsAppearOnce(arr);
        System.out.println(Arrays.toString(ints));
    }
    public int[] FindNumsAppearOnce (int[] array) {
        if(array==null || array.length<2) {
            return new int[]{};
        }
        // write code here
        HashSet<Integer> set = new HashSet<>();
        ArrayList<Integer> arr = new ArrayList<>();
        for (int i=0; i<array.length;i++){
            if (set.contains(array[i])){
                set.remove(array[i]);
            }else {
                set.add(array[i]);
            }
        }
        int [] res = new int[set.size()];
        int size = 0;
        for (Integer value: set) {
            res[size++] = value;
        }
        return res;
    }
}
